/*
 * @(#)TestsetUtil.java
 *
 *
 * ver 1.0 Oct 5, 2007 ggranum
 */
package org.testfire.agent.util;

import java.io.File;
import java.io.IOException;
import org.testfire.agent.AgentProperties;
import org.testfire.model.TestsetType;
import org.testfire.model.exception.CannotParseObjectException;
import org.testfire.util.DOM3XmlReader;
import org.testfire.util.DomReader;
import org.w3c.dom.Document;
import org.w3c.dom.Element;

public class TestsetUtil
{



    public static TestsetType getTestSet( File xmlFile)
    {
        Document doc;
        try
        {
            File f = new File( System.getProperty( "user.dir" ) );
            File schemaDir = new File(f, "resources/tomcat/webapps/ROOT/schema");
            f = new File( schemaDir, "base.xsd" );
            String[] schema = { f.toURI().toString()};


            DOM3XmlReader.SchemaResolver[] resolvers = {
//            new DOM3XmlReader.SchemaResolver( "http://gettestfire.org/schema/base.xsd", f ),
//            new DOM3XmlReader.SchemaResolver( "http://gettestfire.org/schema/watij/Finders.xsd", new File(schemaDir, "watij/Finders.xsd") ),
//            new DOM3XmlReader.SchemaResolver( "http://gettestfire.org/schema/watij/HtmlFinder.xsd", new File(schemaDir, "watij/HtmlFinder.xsd") )
        };

            doc = DOM3XmlReader.getDocument(xmlFile, schema, resolvers );
        }
        catch ( Exception e )
        {
            e.printStackTrace();
            return null;
        }
        Element de = doc.getDocumentElement();
        TestsetType testset;
        try
        {
            testset = new TestsetType( de );
        }
        catch ( CannotParseObjectException e )
        {
            e.printStackTrace();
            return null;
        }
        return testset;
    }


    public static TestsetType getTestSet( String xml)
    {
        try
        {
            return TestsetUtil.getTestSet( DomReader.createTempFileForXMLString( xml));
        }
        catch ( IOException e )
        {
            e.printStackTrace();
            return null;
        }
    }
}

// eof: TestsetUtil.java